package org.yxt.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 将微服务注册到Consul中
 *
 * @author Yang douya
 * @date 2021-1-1
 */
@Slf4j
@RestController
@RequestMapping(value = "payment")
public class Payment2ConsulController {

    @Value("${server.port}")
    private int port;
    @Resource
    private DiscoveryClient discoveryClient;

    /**
     * 测试
     *
     * @return
     */
    @GetMapping(value = "consul")
    public Object consul() {
        List<String> services = discoveryClient.getServices();
        return "当前注册到consul 端口" + port + "服务有 " + services.toString();
    }

}
